﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace ImdbRipperBrowser
{
  public class Config
  {
    public Config(System.Configuration.Configuration config)
    {
      this.config = config;

      ImdbRipperFilesPath = config.AppSettings.Settings["imdbRipperFilesPath"].Value;
      ShowBrowser = bool.Parse(config.AppSettings.Settings["showBrowser"].Value);
      SplitterPosition = int.Parse(config.AppSettings.Settings["splitterPosition"].Value);
      SplitterOrientation = getOrientationFromStr(config.AppSettings.Settings["splitterOrientation"].Value);
      StartMaximized = bool.Parse(config.AppSettings.Settings["startMaximized"].Value);
      Height = int.Parse(config.AppSettings.Settings["height"].Value);
      Width = int.Parse(config.AppSettings.Settings["width"].Value);
    }

    public string ImdbRipperFilesPath { get; set; }
    public bool ShowBrowser { get; set; }
    public int SplitterPosition { get; set; }
    public Orientation SplitterOrientation { get; set; }
    public bool StartMaximized { get; set; }
    public int Height { get; set; }
    public int Width { get; set; }

    private System.Configuration.Configuration config;

    public void Save()
    {
      config.AppSettings.Settings["imdbRipperFilesPath"].Value = ImdbRipperFilesPath;
      config.AppSettings.Settings["showBrowser"].Value = ShowBrowser.ToString();
      config.AppSettings.Settings["splitterPosition"].Value = SplitterPosition.ToString();
      config.AppSettings.Settings["splitterOrientation"].Value = getOrientationFromEnum(SplitterOrientation);
      config.AppSettings.Settings["startMaximized"].Value = StartMaximized.ToString();
      config.AppSettings.Settings["height"].Value = Height.ToString();
      config.AppSettings.Settings["width"].Value = Width.ToString();
      config.Save();
    }

    private static Orientation getOrientationFromStr(string value)
    {
      if (value.Equals("H"))
        return Orientation.Horizontal;
      else
        return Orientation.Vertical;
    }

    private static string getOrientationFromEnum(Orientation value)
    {
      if (value.Equals(Orientation.Horizontal))
        return "H";
      else
        return "V";
    }
  }
}
